import dayjs from "dayjs"

/**
 * 通用混合
 * */
export default {
    data() {
        return {
            // key值为对应表操作的前缀
            tabarr: [
                { key: 'add', name: '新增' },
                { key: 'preArrival', name: '预到' },
                { key: 'arrived', name: '已到' },
                { key: 'overdue', name: '过期未到' },
                { key: 'ordered', name: '预约' },
                { key: 'revision', name: '改约' },
            ],
            // searchData
            type: 2,
            type1:0,
            type2: 2,
            type3: 2,
            type5: 2,
            paramspage: {
                addpage: 1, addpageSize: 10,
                preArrivalpage: 1, preArrivalpageSize: 10,
                arrivedpage: 1, arrivedpageSize: 10,
                overduepage: 1, overduepageSize: 10,
                orderedpage: 1, orderedpageSize: 10,
                revisionpage: 1, revisionpageSize: 10
            },
            options: { disabledDate(date) { return date && date.valueOf() > Date.now() } },
            optionss: { disabledDate(date) { return date && date.valueOf() < Date.now() - 24 * 3600000 } },
            addsearchData: {
                project: [
                    { id: 4, key: 'DatePicker', format: 'yyyy-MM-dd', placeholder: '请选择创建时间', options: { disabledDate(date) { return date && date.valueOf() > Date.now() } }, style: { width: '200px' }, value: [new Date(), new Date()], type: 'daterange', callback: 'changes' },
                    { id: 14, key: 'slot', keys: 'addradio' },
                    { id: 5, key: 'Input', placeholder: '请输入患者姓名/手机号/微信号/唯一身份', clearable: true, style: { width: '270px' }, value: '', callback: 'input' },
                    { id: 6, key: 'Select', style: { minWidth: '100px' }, placeholder: '患者状态', field: { value: 'id', label: 'status_name' }, value: '', childList: [], clearable: true, callback: 'change' },
                    { id: 7, key: 'Select', style: { minWidth: '100px' }, placeholder: '归属人', Group: true, value: `${this.$route.query.member_id || ''}`, childList: [], clearable: true, callback: 'tagchange' },
                    { id: 10, key: 'Select', style: { minWidth: '100px' }, placeholder: '请先选择归属人再选择标签', field: {label: 'tag_name', value: "tag_id"}, Group: true, clearable: true, value: [], childList: [], filterable: true, multiple: true, maxTagCount: 3, callback: 'change' },
                    { id: 8, key: 'TreeSelect', style: { minWidth: '100px' }, placeholder: '病种', value: '', childList: [], clearable: true, callback: 'change' },
                    { id: 12, key: 'Select', style: { minWidth: '100px' }, placeholder: '对话方式', value: '', childList: [], clearable: true, callback: 'change' },
                    { id: 20, key: 'Select', style: { minWidth: '100px' }, placeholder: '部位',multiple: true, maxTagCount: 3, value: [], childList: [], clearable: true, callback: 'change' },
                    { id: 9, key: 'TreeSelect', maxTagCount: 3, style: { minWidth: '100px' }, placeholder: '渠道来源', multiple: true, value: [], childList: [], clearable: true, callback: 'changecasc' },
                    { id: 13, key: 'slot', keys: 'city1' },
                    // { id: 11, key: 'Select', style: { minWidth: '100px' }, placeholder: '城市', value: '', childList: [], clearable: true, callback: 'change' },
                    { id: 3, key: 'slot', keys: 'addcheck' }
                ]
            },
            preArrivalsearchData: {
                project: [
                    { id: 2, key: 'slot', keys: 'preArrivalradio' },
                    { id: 4, key: 'DatePicker', format: 'yyyy-MM-dd', placeholder: '请选择预到时间', options: { disabledDate(date) { return date && date.valueOf() < Date.now() - 24 * 3600000 } }, style: { width: '200px' }, value: [new Date(), new Date()], type: 'daterange', callback: 'changes' },
                    { id: 5, key: 'Input', placeholder: '请输入患者姓名/手机号/微信号/唯一身份', clearable: true, style: { width: '270px' }, value: '', callback: 'input' },
                    { id: 7, key: 'Select', style: { minWidth: '100px' }, placeholder: '归属人', Group: true, value: '', childList: [], clearable: true, callback: 'change' },
                    { id: 8, key: 'TreeSelect', style: { minWidth: '100px' }, placeholder: '病种', value: '', childList: [], clearable: true, callback: 'change' },
                    { id: 12, key: 'Select', style: { minWidth: '100px' }, placeholder: '对话方式', value: '', childList: [], clearable: true, callback: 'change' },
                    { id: 20, key: 'Select', style: { minWidth: '100px' }, placeholder: '部位',multiple: true, maxTagCount: 3, value: [], childList: [], clearable: true, callback: 'change' },
                    { id: 9, key: 'TreeSelect', maxTagCount: 3, style: { minWidth: '100px' }, placeholder: '渠道来源', multiple: true, value: [], childList: [], clearable: true, callback: 'changecasc' },
                    { id: 13, key: 'slot', keys: 'city2' },
                    // { id: 11, key: 'Select', style: { minWidth: '100px' }, placeholder: '城市', value: '', childList: [], clearable: true, callback: 'change'},
                ]
            },
            arrivedsearchData: {
                project: [
                    { id: 1, key: 'slot', keys: 'arrivedradio' },
                    { id: 4, key: 'DatePicker', format: 'yyyy-MM-dd', placeholder: '请选择已到时间', options: { disabledDate(date) { return date && date.valueOf() > Date.now() } }, style: { width: '200px' }, value: [new Date(), new Date()], type: 'daterange', callback: 'changes' },
                    { id: 5, key: 'Input', placeholder: '请输入患者姓名/手机号/微信号/唯一身份', clearable: true, style: { width: '270px' }, value: '', callback: 'input' },
                    { id: 7, key: 'Select', style: { minWidth: '100px' }, placeholder: '归属人', Group: true, value: '', childList: [], clearable: true, callback: 'change' },
                    { id: 8, key: 'TreeSelect', style: { minWidth: '100px' }, placeholder: '病种', value: '', childList: [], clearable: true, callback: 'change' },
                    { id: 12, key: 'Select', style: { minWidth: '100px' }, placeholder: '对话方式', value: '', childList: [], clearable: true, callback: 'change' },
                    { id: 20, key: 'Select', style: { minWidth: '100px' }, placeholder: '部位',multiple: true, maxTagCount: 3, value: [], childList: [], clearable: true, callback: 'change' },
                    { id: 9, key: 'TreeSelect', maxTagCount: 3, style: { minWidth: '100px' }, placeholder: '渠道来源', multiple: true, value: [], childList: [], clearable: true, callback: 'changecasc' },
                    { id: 13, key: 'slot', keys: 'city3' },
                    // { id: 11, key: 'Select', style: { minWidth: '100px' }, placeholder: '城市', value: '', childList: [], clearable: true, callback: 'change'},
                ]
            },
            overduesearchData: {
                project: [
                    { id: 5, key: 'Input', placeholder: '请输入患者姓名/手机号/微信号/唯一身份', clearable: true, style: { width: '270px' }, value: '', callback: 'input' },
                    { id: 7, key: 'Select', style: { minWidth: '100px' }, placeholder: '归属人', Group: true, value: '', childList: [], clearable: true, callback: 'change' },
                    { id: 8, key: 'TreeSelect', style: { minWidth: '100px' }, placeholder: '病种', value: '', childList: [], clearable: true, callback: 'change' },
                    { id: 12, key: 'Select', style: { minWidth: '100px' }, placeholder: '对话方式', value: '', childList: [], clearable: true, callback: 'change' },
                    { id: 20, key: 'Select', style: { minWidth: '100px' }, placeholder: '部位',multiple: true, maxTagCount: 3, value: [], childList: [], clearable: true, callback: 'change' },
                    { id: 9, key: 'TreeSelect', maxTagCount: 3, style: { minWidth: '100px' }, placeholder: '渠道来源', multiple: true, value: [], childList: [], clearable: true, callback: 'changecasc' },
                    { id: 13, key: 'slot', keys: 'city4' },
                    // { id: 11, key: 'Select', style: { minWidth: '100px' }, placeholder: '城市', value: '', childList: [], clearable: true, callback: 'change'},
                ]
            },
            orderedsearchData: {
                project: [
                    { id: 1, key: 'slot', keys: 'orderedradio' },
                    { id: 4, key: 'DatePicker', format: 'yyyy-MM-dd', placeholder: '请选择预约时间', options: { disabledDate(date) { return date && date.valueOf() > Date.now() } }, style: { width: '200px' }, value: [new Date(), new Date()], type: 'daterange', callback: 'changes' },
                    { id: 5, key: 'Input', placeholder: '请输入患者姓名/手机号/微信号/唯一身份', clearable: true, style: { width: '270px' }, value: '', callback: 'input' },
                    { id: 6, key: 'Select', style: { minWidth: '100px' }, placeholder: '患者状态', field: { value: 'id', label: 'status_name' }, value: '', childList: [], clearable: true, callback: 'change' },
                    { id: 7, key: 'Select', style: { minWidth: '100px' }, placeholder: '归属人', Group: true, value: '', childList: [], clearable: true, callback: 'change' },
                    { id: 8, key: 'TreeSelect', style: { minWidth: '100px' }, placeholder: '病种', value: '', childList: [], clearable: true, callback: 'change' },
                    { id: 12, key: 'Select', style: { minWidth: '100px' }, placeholder: '对话方式', value: '', childList: [], clearable: true, callback: 'change' },
                    { id: 20, key: 'Select', style: { minWidth: '100px' }, placeholder: '部位',multiple: true, maxTagCount: 3, value: [], childList: [], clearable: true, callback: 'change' },
                    { id: 9, key: 'TreeSelect', maxTagCount: 3, style: { minWidth: '100px' }, placeholder: '渠道来源', multiple: true, value: [], childList: [], clearable: true, callback: 'changecasc' },
                    { id: 13, key: 'slot', keys: 'city5' },
                    // { id: 11, key: 'Select', style: { minWidth: '100px' }, placeholder: '城市', value: '', childList: [], clearable: true, callback: 'change'},
                    { id: 10, key: 'Select', style: { minWidth: '100px' }, placeholder: '请先选择归属人再选择标签', Group: true, clearable: true, value: [], childList: [], filterable: true, multiple: true, maxTagCount: 3, callback: 'change' }
                ]
            },
            revisionsearchData: {
                project: [
                    { id: 5, key: 'Input', placeholder: '请输入患者姓名/手机号/微信号/唯一身份', clearable: true, style: { width: '270px' }, value: '', callback: 'input' },
                    { id: 7, key: 'Select', style: { minWidth: '100px' }, placeholder: '归属人', Group: true, value: '', childList: [], clearable: true, callback: 'change' },
                    { id: 8, key: 'TreeSelect', style: { minWidth: '100px' }, placeholder: '病种', value: '', childList: [], clearable: true, callback: 'change' },
                    { id: 12, key: 'Select', style: { minWidth: '100px' }, placeholder: '对话方式', value: '', childList: [], clearable: true, callback: 'change' },
                    { id: 20, key: 'Select', style: { minWidth: '100px' }, placeholder: '部位',multiple: true, maxTagCount: 3, value: [], childList: [], clearable: true, callback: 'change' },
                    { id: 9, key: 'TreeSelect', maxTagCount: 3, style: { minWidth: '100px' }, placeholder: '渠道来源', multiple: true, value: [], childList: [], clearable: true, callback: 'changecasc' },
                    { id: 13, key: 'slot', keys: 'city6' },
                    // { id: 11, key: 'Select', style: { minWidth: '100px' }, placeholder: '城市', value: '', childList: [], clearable: true, callback: 'change'},
                ]
            }
        }
    },
    methods: {
        inputaskData() {
            this.params.page = 1
            this.type = undefined
            this.searchData.project.forEach(item => {
                if (item.id === 5) {
                    this.params.keywords = item.value
                } else if (item.id === 4) {
                    let keywording = ''
                    this.searchData.project.forEach(items =>{
                        if (items.id === 5) {
                            keywording = items.value
                        }
                    })
                    if (keywording !== '') {
                        if (JSON.stringify(item.value) !== JSON.stringify(["", ""])) {
                            let timer = [dayjs(item.value[0]).format('YYYY-MM-DD'),dayjs(item.value[1]).format('YYYY-MM-DD')]
                            if (this.currentTab === "add") {
                                this.type1 = undefined
                                this.storage.set('patient-add',timer )
                            } else if (this.currentTab === "preArrival") {
                                this.type2 = undefined
                                this.storage.set('patient-preArrival',timer )
                            } else if (this.currentTab === "arrived") {
                                this.type3 = undefined
                                this.storage.set('patient-arrived',timer )
                            }else if (this.currentTab === "ordered") {
                                this.type5 = undefined
                                this.storage.set('patient-ordered',timer )
                            }
                            item.value = ["", ""];
                            this.params.created_stime = ''
                            this.params.created_etime = ''
                            this.params.appointment_stime = ''
                            this.params.appointment_etime = ''
                            this.params.revisiting_stime = ''
                            this.params.revisiting_etime = ''
                            this.params.operate_stime = ''
                            this.params.operate_etime = ''
                        }
                    } else {
                        if (this.currentTab === "add") {
                            if (JSON.stringify(this.storage.get('patient-add'))!== JSON.stringify(["", ""])) {
                                item.value = this.storage.get('patient-add')
                            }
                        } else if (this.currentTab === "preArrival") {
                            if (JSON.stringify(this.storage.get('patient-preArrival'))!== JSON.stringify(["", ""])) {
                                item.value = this.storage.get('patient-preArrival')
                            }
                        } else if (this.currentTab === "arrived") {
                            if (JSON.stringify(this.storage.get('patient-arrived'))!== JSON.stringify(["", ""])) {
                                item.value = this.storage.get('patient-arrived')
                            }
                        }else if (this.currentTab === "ordered") {
                            if (JSON.stringify(this.storage.get('patient-ordered'))!== JSON.stringify(["", ""])) {
                                item.value = this.storage.get('patient-ordered')
                            }
                        }
                        this.params.created_stime = item.value[0]
                        this.params.created_etime = item.value[1]
                        this.params.appointment_stime = item.value[0]
                        this.params.appointment_etime = item.value[1]
                        this.params.revisiting_stime = item.value[0]
                        this.params.revisiting_etime = item.value[1]
                        this.params.operate_stime = item.value[0]
                        this.params.operate_etime = item.value[1]
                    }
                } else if (item.id === 6) {
                    item.value = ''
                    this.params.patient_status_id = ''
                } else if (item.id === 7) {
                    item.value = ''
                    this.params.belong_member_id = ''
                } else if (item.id === 8) {
                    item.value = ''
                    this.params.patient_diseases_id = ''
                } else if (item.id === 9) {
                    item.value = ''
                    this.params.channel_id = []
                } else if (item.id === 10) {
                    item.value = []
                    this.params.tags_ids = ''
                } else if (item.id === 12) {
                    item.value = []
                    this.params.dialog_mode_id = ''
                } else if (item.id === 20) {
                    item.value = []
                    this.params.body_parts_id = ''
                }
            })
            this.paramsreset()
            this.askData()
        },
        changecasc(e) {
            this.params.page = 1
            this.params.channel_id = [e]
            this.searchData.project.forEach(item => {
                if (item.id === 4) {
                    this.params.created_stime = item.value[0]
                    this.params.created_etime = item.value[1]
                    this.params.appointment_stime = item.value[0]
                    this.params.appointment_etime = item.value[1]
                    this.params.revisiting_stime = item.value[0]
                    this.params.revisiting_etime = item.value[1]
                    this.params.operate_stime = item.value[0]
                    this.params.operate_etime = item.value[1]
                }
            })
            this.paramsreset()
            this.askData()
        },
        getDatas() {
            this.params.page = 1
            this.searchData.project.forEach(item => {
                if (item.id === 4) {
                    this.params.created_stime = item.value[0]
                    this.params.created_etime = item.value[1]
                    this.params.appointment_stime = item.value[0]
                    this.params.appointment_etime = item.value[1]
                    this.params.revisiting_stime = item.value[0]
                    this.params.revisiting_etime = item.value[1]
                    this.params.operate_stime = item.value[0]
                    this.params.operate_etime = item.value[1]
                } else if (item.id === 5) {
                    this.params.keywords = item.value
                } else if (item.id === 6) {
                    this.params.patient_status_id = item.value
                } else if (item.id === 7) {
                    this.params.belong_member_id = item.value
                } else if (item.id === 8) {
                    this.params.patient_diseases_id = item.value
                } else if (item.id === 9) {
                    this.params.channel_id = item.value
                } else if (item.id === 10) {
                    this.params.tags_ids = item.value.join(',')
                } else if (item.id === 12) {
                    this.params.dialog_mode_id = item.value
                } else if (item.id === 20) {
                    this.params.body_parts_id = item.value.join(',')
                }
            })
            this.paramsreset()
            this.askData()
        },
        gettagDatas() {
            let member_id = ''
            this.searchData.project.forEach(item => {
                if (item.id === 7) {
                    member_id = item.value
                }
            })
            this.customerwechattagslist({member_id}).then(res=>{
                this.searchData.project.forEach(item => {
                    if (item.id === 10) {
                        item.childList = res.list[0].tags
                        this.logs(item,res.list[0].tags)
                    }
                })
                this.getDatas()
            })
        },
        getDatass() {
            for (let item of this.columns) {
                if (item.title ===  "未访天数") {
                    item.filteredValue = []
                    this.params.not_callback_start = ""
                    this.params.not_callback_end = ""
                }
            }
            if (this.currentTab === "add") {
                this.type1 = undefined;
            } else if (this.currentTab === "preArrival") {
                this.type2 = undefined;
            } else if (this.currentTab === "arrived") {
                this.type3 = undefined;
            } else if (this.currentTab === "ordered") {
                this.type5 = undefined;
            }
            this.params.page = 1
            this.searchData.project.forEach(item => {
                if (item.id === 4) {
                    let timer = ["",""]
                    if (JSON.stringify(item.value) !== JSON.stringify(["", ""])){
                        timer = [dayjs(item.value[0]).format('YYYY-MM-DD'),dayjs(item.value[1]).format('YYYY-MM-DD')]
                    } 
                    if (this.currentTab === "add") {
                        this.storage.set('patient-add',timer )
                    } else if (this.currentTab === "preArrival") {
                        this.storage.set('patient-preArrival',timer )
                    } else if (this.currentTab === "arrived") {
                        this.storage.set('patient-arrived',timer )
                    }else if (this.currentTab === "ordered") {
                        this.storage.set('patient-ordered',timer )
                    }
                    this.params.created_stime = item.value[0]
                    this.params.created_etime = item.value[1]
                    this.params.appointment_stime = item.value[0]
                    this.params.appointment_etime = item.value[1]
                    this.params.revisiting_stime = item.value[0]
                    this.params.revisiting_etime = item.value[1]
                    this.params.operate_stime = item.value[0]
                    this.params.operate_etime = item.value[1]
                }
            })
            this.paramsreset()
            this.askData()
        },
        changetype(type) {
            for (let item of this.columns) {
                if (item.title ===  "未访天数") {
                    item.filteredValue = []
                    this.params.not_callback_start = ""
                    this.params.not_callback_end = ""
                }
            }
            let week = dayjs().day()
            let weekday = dayjs().add(7 - week, 'day').format('YYYY-MM-DD')
            let today = dayjs().format('YYYY-MM-DD')
            let yesday = dayjs().subtract(1, 'day').format('YYYY-MM-DD')
            let tomday = dayjs().add(1, 'day').format('YYYY-MM-DD')
            let sday = dayjs(`${dayjs().format('YYYY-MM')}-1`).format('YYYY-MM-DD')
            let eday = dayjs(`${dayjs().year()}-${dayjs().month()+2}`).subtract(1, 'day').format('YYYY-MM-DD')
            this.searchData.project.forEach(item => {
                if (item.id === 4) {
                    if (type === 1) item.value = [yesday, yesday]
                    if (type === 2) item.value = [today, today]
                    if (type === 3) item.value = [tomday, tomday]
                    if (type === 4) item.value = [today, weekday]
                    if (type === 5) item.value = [sday, eday]

                    this.params.created_stime = item.value[0]
                    this.params.created_etime = item.value[1]
                    this.params.appointment_stime = item.value[0]
                    this.params.appointment_etime = item.value[1]
                    this.params.revisiting_stime = item.value[0]
                    this.params.revisiting_etime = item.value[1]
                    this.params.operate_stime = item.value[0]
                    this.params.operate_etime = item.value[1]
                }
            })
            this.paramsreset()
            this.askData()
        }
    }
}